using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using MM.Entities;

namespace MM.Business
{
    class clsCAY_PHAN_CAP_QUYEN
    {
        public clsCAY_PHAN_CAP_QUYEN(string sConn)
	    {
		    SqlHelper.ConnectionString = sConn;
	    }
        public List<CAY_PHAN_CAP_QUYEN> DataTableToLstObj(DataTable dt)
        {
            CAY_PHAN_CAP_QUYEN cpcQuyenDTO;
            List<CAY_PHAN_CAP_QUYEN> lstCpcQuyenDTO = new List<CAY_PHAN_CAP_QUYEN>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cpcQuyenDTO = new CAY_PHAN_CAP_QUYEN();
                try
                {
                    cpcQuyenDTO._tenForm = dt.Rows[i]["TenForm"].ToString();
                }
                catch 
                {
                }
                try
                {
                    cpcQuyenDTO._bac= int.Parse(dt.Rows[i]["Bac"].ToString());
                }
                catch 
                {
                }
                try
                {
                    cpcQuyenDTO._tenFormCha = dt.Rows[i]["TenFormCha"].ToString();
                }
                catch 
                {
                }
                lstCpcQuyenDTO.Add(cpcQuyenDTO);
            }
            return lstCpcQuyenDTO;
        }
        public CAY_PHAN_CAP_QUYEN DataTableToObj(DataTable dt)
        {
            CAY_PHAN_CAP_QUYEN cpcQuyenDTO = new CAY_PHAN_CAP_QUYEN();
            try
            {
                cpcQuyenDTO._tenForm = dt.Rows[0]["TenForm"].ToString();
            }
            catch 
            {
            }
            try
            {
                cpcQuyenDTO._bac = int.Parse(dt.Rows[0]["Bac"].ToString());
            }
            catch 
            {
            }
            try
            {
                cpcQuyenDTO._tenFormCha = dt.Rows[0]["TenFormCha"].ToString();
            }
            catch 
            {
            }
            return cpcQuyenDTO;
        }
        public CAY_PHAN_CAP_QUYEN SelectCAY_PHAN_CAP_QUYEN(string tenForm)
        {
            DataTable dt = new DataTable();
            CAY_PHAN_CAP_QUYEN cpcQuyenDTO = new CAY_PHAN_CAP_QUYEN();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectCAY_PHAN_CAP_QUYEN";
                SqlParameter[] par = new SqlParameter[1];
                par[0] = new SqlParameter("@TenForm", tenForm);
                dt = SqlHelper.ExecuteToDataTable(spName, par);
                cpcQuyenDTO = DataTableToObj(dt);
            }
            catch 
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return cpcQuyenDTO;
        }
        
    }
}
